<template>
  <div class="detail" :style="contentData.style" :class="isActiveClass">
    <div class="name" :style="nameStyle">{{ contentData.name || 'xx驾校' }}</div>

    <div class="tag">
      <div class="item" v-for="(tag, index) in contentData.tags" :key="index" :style="tagStyle">
        {{ tag }}
      </div>
    </div>

    <div class="business-hours" :style="timeStyle">
      <div>{{ contentData.businessHours || '营业时间 周一至周日00:00-24:00' }}</div>
      <div v-if="contentData.showMore">更多</div>
    </div>

    <div class="line"></div>

    <div class="address">
      <div class="address-info">
        <div class="address-range" :style="addressMainStyle">
          {{ contentData.address }}
        </div>
        <div class="address-road" :style="addressSubStyle"> 距离{{ contentData.distance }} </div>
      </div>
      <div class="icon-list" v-if="contentData.showIcons">
        <div class="info-icon">
          <el-icon><Location /></el-icon>
          <div class="icon-text">地图</div>
        </div>
        <div class="info-icon">
          <el-icon><Phone /></el-icon>
          <div class="icon-text">电话</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { Phone, Location } from '@element-plus/icons-vue'

  const props = defineProps({
    contentData: {
      type: Object,
      default() {
        return {}
      }
    },
    isActiveClass: {
      type: String
    }
  })

  const nameStyle = computed(() => {
    const s = props.contentData.nameStyle || {}
    return {
      fontSize: s.fontSize ? s.fontSize + 'px' : undefined,
      color: s.color,
      fontWeight: s.fontWeight
    }
  })

  const tagStyle = computed(() => {
    const s = props.contentData.tagStyle || {}
    return {
      fontSize: s.fontSize ? s.fontSize + 'px' : undefined,
      color: s.color,
      fontWeight: s.fontWeight,
      backgroundColor: s.backgroundColor,
      borderRadius: s.borderRadius ? s.borderRadius + 'rpx' : undefined
    }
  })

  const timeStyle = computed(() => {
    const s = props.contentData.timeStyle || {}
    return {
      fontSize: s.fontSize ? s.fontSize + 'px' : undefined,
      color: s.color,
      fontWeight: s.fontWeight
    }
  })

  const addressMainStyle = computed(() => {
    const s = props.contentData.addressMainStyle || {}
    return {
      fontSize: s.fontSize ? s.fontSize + 'px' : undefined,
      color: s.color,
      fontWeight: s.fontWeight
    }
  })

  const addressSubStyle = computed(() => {
    const s = props.contentData.addressSubStyle || {}
    return {
      fontSize: s.fontSize ? s.fontSize + 'px' : undefined,
      color: s.color,
      fontWeight: s.fontWeight
    }
  })
</script>

<style scoped lang="scss">
  .detail {
    background: linear-gradient(#d8f1ee, #fff);
    padding: 20px;
    box-sizing: border-box;

    .tag {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      margin: 8px 0;

      .item {
        padding: 4px 12px;
        margin-right: 10px;
      }
    }

    .business-hours {
      margin: 10px 0;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .line {
      width: 100%;
      height: 1px;
      background-color: #e1e6ed;
      margin: 10px 0;
    }

    .address {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .icon-list {
        display: flex;

        .info-icon {
          margin-left: 20px;
          display: flex;
          flex-direction: column;
          align-items: center;

          .icon-text {
            font-size: 12px;
            color: #666;
            margin-top: 4px;
          }
        }
      }
    }
  }

  .active-component {
    border: 1px solid var(--el-color-primary);
  }
</style>
